package com.yuan.plugin.view;

import com.yuan.myplugin.R;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;

public class ImageDialog extends Dialog {

	private String msg;
	private Context context;

	private static ImageDialog dialog;

	public static synchronized void showDialog(Context context, String msg) {
		if (dialog == null) {
			dialog = new ImageDialog(context, msg);
		}
		if (!dialog.isShowing()) {
			if(context instanceof Activity){
				if(!((Activity) context).isFinishing()){
					dialog.show();		
				}
			}else{
				dialog.show();
			}
		}

	}
	public static synchronized void showDialog(Context context) {
		if (dialog == null) {
			dialog = new ImageDialog(context, "");
		}
		if (!dialog.isShowing()) {
			if(context instanceof Activity){
				if(!((Activity) context).isFinishing()){
					dialog.show();		
				}
			}else{
				dialog.show();
			}
		}

	}
	public static synchronized void closeDialog() {
		if (dialog != null) {
			dialog.dismiss();
			dialog = null;
		}
	}

	public ImageDialog(Context context, String msg) {
		super(context, R.style.dialog);
		// setCancelable(false);
		setCanceledOnTouchOutside(false);

		this.context = context;
		this.msg = msg;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.toast_default);
	}
}
